package com.example.wemedia.service;

import org.apache.commons.lang3.time.DateUtils;
import org.springframework.util.DigestUtils;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

public class test {
    public static void main(String[] args) {
        List<Date> dates = getSevenDate();
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
        for (int i = 0; i < dates.size(); i++) {
            System.out.println(dateFormat.format(dates.get(i)));
        }
    }

    public static List<Date> getSevenDate() {
        List<Date> dateList = new ArrayList<>();
        for (int i = 0; i < 7; i++) {
            Date date = DateUtils.addDays(new Date(), -i);
//            String formatDate = sdf.format(date);
            dateList.add(date);
        }
        return dateList;
    }

    public static List<Date> getSevenDaysList() {
        List<Date> sevenDaysList = new ArrayList<>();
        Calendar calendar = Calendar.getInstance();
        for (int i = 0; i < 7; i++) {
            calendar.add(Calendar.DAY_OF_YEAR, i == 0 ? 0 : 1);
            sevenDaysList.add(calendar.getTime());
            calendar.add(Calendar.DAY_OF_YEAR, -i); // Reset back to today
        }
        return sevenDaysList;
    }
}
